<template>
  <section class="recommended-products">
    <h2>{{ name }}</h2>
    <el-row :gutter="20">
      <el-col v-for="product in products" :key="product.id" :span="6">
        <el-card class="product-card" style="{ padding: 20px; }">
          <img :src="product.image" class="product-image" alt="商品图片" />
          <div class="product-info">
            <h3 class="product-name">{{ product.name }}</h3>
            <p class="product-price">￥{{ product.price }}</p>
            <el-button type="primary" @click="addToCart(product)">加入购物车</el-button>
          </div>
        </el-card>
      </el-col>
    </el-row>
  </section>
</template>

<script setup>
import {ref} from "vue";

const props = defineProps({
  products: {
    type: Array,
    required: true,
  },
  name:{
    required:true,
  }
});

// const products = ref([
//   { id: 1, name: '商品1', price: 100, image: 'path/to/image1.jpg' },
//   { id: 2, name: '商品2', price: 150, image: 'path/to/image2.jpg' },
//   { id: 3, name: '商品3', price: 200, image: 'path/to/image3.jpg' },
//   { id: 4, name: '商品4', price: 250, image: 'path/to/image4.jpg' },
// ])

const addToCart = (product) => {
  console.log(`添加到购物车: ${product.name}`);
}
</script>

<style scoped>
.recommended-products {
  padding: 20px;
  background-color: #fff;
}
.product-card {
  text-align: center;
}
.product-image {
  width: 100%;
  height: auto;
}
.product-name {
  font-size: 16px;
  margin: 10px 0;
}
.product-price {
  color: #f56c6c;
  font-size: 18px;
  margin: 10px 0;
}
</style>